<template>
  <div class="maina">
    <arrow :topList="topList"></arrow>
    <div>
      <div class="content">
        <article class="content_box">
          <div class="title_left">审核管理 > 待审核内容</div>

          <!-- <div @click="goEdit()">点我详情list，编辑或者添加</div> -->

          <div class="app-container">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
              >
              <el-form-item label="关键词：" prop="keyword">
                <el-input v-model="queryParams.keyWords" placeholder="请输入关键词" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <!-- <el-form-item label="进度(1：素材归集中 ,2：内容创作中,3：创作已完成、4：已提交审核 5：已收入成品库、6：产品分发中)" prop="schedule">
                <el-input v-model="queryParams.schedule"
                  placeholder="请输入进度(1：素材归集中 ,2：内容创作中,3：创作已完成、4：已提交审核 5：已收入成品库、6：产品分发中)" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item> -->
              <el-form-item label="内容状态" prop="type" label-width="100px">
                <el-select v-model="queryParams.articleExamineState" placeholder="请选择">
                  <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- <el-form-item label="展示编号" prop="topicXh">
                <el-input v-model="queryParams.topicXh" placeholder="请输入展示编号" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>

              <el-form-item label="目标" prop="target">
                <el-input v-model="queryParams.target" placeholder="请输入目标" clearable @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="预期成果" prop="results">
                <el-input v-model="queryParams.results" placeholder="请输入预期成果" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>

              <el-form-item label="操作人ID" prop="userId">
                <el-input v-model="queryParams.userId" placeholder="请输入操作人ID" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="操作人姓名" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入操作人姓名" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="是否删除   -1：已删除，0：未删除" prop="isDelete">
                <el-input v-model="queryParams.isDelete" placeholder="请输入是否删除   -1：已删除，0：未删除" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="时间周期开始时间" prop="startTime">
                <el-date-picker clearable v-model="queryParams.startTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择时间周期开始时间">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="时间周期 结束时间" prop="endTime">
                <el-date-picker clearable v-model="queryParams.endTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择时间周期 结束时间">
                </el-date-picker>
              </el-form-item> -->

              <el-form-item>
                <el-button type="primary" icon="el-icon-search" style="background-color: #165DFF;border-color: #165DFF;"
                  @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>

            <el-row :gutter="10" class="mb8">
              <!-- <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                  v-hasPermi="['system:topic:add']">新增</el-button>
              </el-col> -->
              <!-- <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                  v-hasPermi="['system:topic:edit']">修改</el-button>
              </el-col> -->
              <!-- <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                  @click="handleDelete" v-hasPermi="['system:topic:remove']">删除</el-button>
              </el-col> -->
              <!-- <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                  v-hasPermi="['system:topic:export']">导出</el-button>
              </el-col> -->
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <el-table stripe v-loading="loading" :data="topicList" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="内容编号" label-width="80px" prop="topicXh" />
              <!-- <el-table-column label="展示编号" align="center" prop="topicXh" /> -->
              <el-table-column label="内容名称" align="center" prop="title" />
              <el-table-column label="内容目标" align="center" prop="target" />
              <el-table-column label="课题开始时间" align="center" prop="startTime" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="内容类型" align="center" prop="type" />
              <el-table-column label="内容状态" align="center" prop="articleExamineState" />
              <el-table-column label="是否原创" align="center" prop="copyrightType" />
              <el-table-column label="审核人" align="center" prop="actualExamineUserid" />
              <el-table-column label="审核意见" align="center" prop="examineFailedReason" />


              <!-- <el-table-column label="操作人ID" align="center" prop="userId" />
              <el-table-column label="操作人姓名" align="center" prop="userName" />
              <el-table-column label="是否删除   -1：已删除，0：未删除" align="center" prop="isDelete" />
              <el-table-column label="关联素材id " align="center" prop="sourceMaterialId" />
              <el-table-column label="时间周期开始时间" align="center" prop="startTime" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="大纲" align="center" prop="outline" />
              <el-table-column label="预期成果" align="center" prop="results" /> -->

              <el-table-column label="操作" fixed="right" align="center" width="200"  class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button  icon="el-icon-search" size="small"  @click="handleUpdate(scope.row)">预览</el-button>
                  <el-button icon="el-icon-monitor" type="success" plain  size="small" @click="handleExam(scope.row)">审核</el-button>

                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize" @pagination="getList" />

            <!-- 添加或修改文章选题对话框 -->
            <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
              <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="展示编号" prop="topicXh">
                  <el-input v-model="form.topicXh" placeholder="请输入展示编号" />
                </el-form-item>
                <el-form-item label="标题" prop="title">
                  <el-input v-model="form.title" placeholder="请输入标题" />
                </el-form-item>
                <el-form-item label="目标" prop="target">
                  <el-input v-model="form.target" placeholder="请输入目标" />
                </el-form-item>
                <el-form-item label="内容摘要" prop="digest">
                  <el-input v-model="form.digest" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="大纲" prop="outline">
                  <el-input v-model="form.outline" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="预期成果" prop="results">
                  <el-input v-model="form.results" placeholder="请输入预期成果" />
                </el-form-item>
                <el-form-item label="进度" prop="schedule">
                  <el-input v-model="form.schedule" placeholder="请输入进度" />
                </el-form-item>
                <el-form-item label="操作人ID" prop="userId">
                  <el-input v-model="form.userId" placeholder="请输入操作人ID" />
                </el-form-item>
                <el-form-item label="操作人姓名" prop="userName">
                  <el-input v-model="form.userName" placeholder="请输入操作人姓名" />
                </el-form-item>
                <el-form-item label="是否删除   -1：已删除，0：未删除" prop="isDelete">
                  <el-input v-model="form.isDelete" placeholder="请输入是否删除   -1：已删除，0：未删除" />
                </el-form-item>
                <el-form-item label="关联素材id " prop="sourceMaterialId">
                  <el-input v-model="form.sourceMaterialId" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="时间周期开始时间" prop="startTime">
                  <el-date-picker clearable v-model="form.startTime" type="date" value-format="yyyy-MM-dd"
                    placeholder="请选择时间周期开始时间">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="时间周期 结束时间" prop="endTime">
                  <el-date-picker clearable v-model="form.endTime" type="date" value-format="yyyy-MM-dd"
                    placeholder="请选择时间周期 结束时间">
                  </el-date-picker>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
              </div>
            </el-dialog>
          </div>


          <shenheView :preOpen="shenhe" :isTwo="true" :myRow="myRow" :isForm="true" @updatePre="updateshenhe" @flushList="getList"></shenheView>
          <shenheView :preOpen="preOpen" :myRow="myRow" :isForm="false" @updatePre="updatePre"></shenheView>
        </article>
      </div>
    </div>
  </div>
</template>

<script>
import shenheView from '@/views/components/shenheview'
import arrow from '@/views/components/arrow'
import { listTopic, delMytopicChuGao } from '@/api/my/xuanti'
import { shenheList } from '@/api/my'

export default {
  components: { arrow, shenheView },
  name: '',
  data() {
    return {
      shenhe: false,
      myRow: {},  //要传的id
      preOpen: false,   //预览dialog开关
      invation: {
        name: '',  //邀请人姓名
        phone: '',
        job: '',
        url: ''
      },
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      pop: {
        title: '',  //所选专家
        search: '', //搜索专家
      },
      activeName: 'first',
      options: [{
        value: '黄金糕',
        label: '黄金糕'
      }, {
        value: '双皮奶',
        label: '双皮奶'
      }, {
        value: '蚵仔煎',
        label: '蚵仔煎'
      }, {
        value: '龙须面',
        label: '龙须面'
      }, {
        value: '北京烤鸭',
        label: '北京烤鸭'
      }],
      value: '',
      openTiShen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文章选题表格数据
      topicList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyWords: null,
        examineType: "2",
        examineState: "2"
        // articleExamineState: null,
        // topicXh: null,
        // target: null,
        // digest: null,
        // outline: null,
        // results: null,
        // type: null,
        // schedule: null,
        // userId: null,
        // userName: null,
        // isDelete: null,
        // sourceMaterialId: null,
        // startTime: null,
        // endTime: null
      },
      processList: [
        { value: 1, label: '素材归集中' },
        { value: 2, label: '内容创作中' },
        { value: 3, label: '创作已完成' },
        { value: 4, label: '已提交审核' },
        { value: 5, label: '已收入成品库' },
        { value: 6, label: '产品分发中' },
      ],
      contentType: [
        { value: 1, label: '图片' },
        { value: 2, label: '视频' },
        { value: 3, label: '音频' },
        { value: 4, label: '动漫' },
        { value: 5, label: '挂图' },
      ],
      status: [
        { value: 1, label: '待审核' },
        { value: 2, label: '审核中' },
        { value: 3, label: '审核通过' },
        { value: 4, label: '审核未通过' },
        { value: 5, label: '拒绝审核' },
      ],
      protos: [
        { value: 1, label: '原创' },
        { value: 2, label: '网络' },
        { value: 3, label: '委托' },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // userId: [
        //   { required: true, message: "操作人ID不能为空", trigger: "blur" }
        // ],
        // userName: [
        //   { required: true, message: "操作人姓名不能为空", trigger: "blur" }
        // ],
        // createTime: [
        //   { required: true, message: "创建时间不能为空", trigger: "blur" }
        // ],
      },
      topList: {
        title: '流程指引',
        list: [
          { name: '素材管理', img: 'blue' },
          { name: '内容创作', img: 'blue' },
          { name: '专家审核', img: 'blue' },
          { name: '产品分发', img: 'gray' },
          { name: '传播管理', img: 'gray' },
        ]
      },
    }
  },
  created() {
    this.getList();
  },
  methods: {
    preview(row) {
      this.myRow = row
      this.preOpen = true
    },
    updateshenhe(val) {
      this.shenhe = val
    },
    updatePre(val) {
      this.preOpen = val
    },
    handleClick(tab, event) {
      //  console.log(tab, event);
    },
    handleExam(row) {  //提审
      this.myRow = row
      this.shenhe = true
      //  this.openTiShen = true

      // console.log(123);
    },
    goEdit() {
      this.$router.push({ path: 'xuanti_edit' })
    },
    /** 查询文章选题列表 */
    getList() {
      this.loading = false;
      shenheList(this.queryParams).then(response => {
        response.rows.map(v => {
          let typeFind = this.contentType.find(values => values.value == v.type)
          if (typeFind !== undefined) {  //内容类型
            v.type = typeFind.label
          }
          let statusFind = this.status.find(r => r.value == v.articleExamineState)
          if (statusFind !== undefined) {  //审核状态
            v.articleExamineState = statusFind.label
          }
          let protosFind = this.protos.find(params => params.value == v.copyrightType)
          if (protosFind !== undefined) {
            v.copyrightType = protosFind.label
          }
          v.digest = this.$cutString(v.digest,8)
         v.target = this.$cutString(v.target,8)
         v.title = this.$cutString(v.title,8)
          return v
          // console.log(v);

        })
        this.topicList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        topicId: null,
        topicXh: null,
        keyword: null,
        target: null,
        digest: null,
        outline: null,
        results: null,
        type: null,
        schedule: null,
        userId: null,
        userName: null,
        isDelete: null,
        createTime: null,
        updateTime: null,
        sourceMaterialId: null,
        startTime: null,
        endTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.topicId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增文章选题";
      this.$router.push({ path: '/content/xuanti_edit', 'query': { 'type': 1 } })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.preview(row)
      //this.preview(row)
      // this.reset();
      // const topicId = row.topicId || this.ids
      // getTopic(topicId).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改文章选题";
      // });
      // console.log(row);
      // this.$router.push({ path: '/content/edit_content', query: { 'type': 2, 'articleId': row.articleId, 'topicId': row.topicId } })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.topicId != null) {
            updateTopic(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTopic(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const articleId = row.articleId || row.topicId || this.ids;
      this.$modal.confirm('是否确认删除内容编号为"' + row.topicXh + '"的数据项？').then(function () {
        // return delTopic(topicIds);
        return delMytopicChuGao(articleId)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/topic/export', {
        ...this.queryParams
      }, `topic_${new Date().getTime()}.xlsx`)
    }
  },

}
</script>
<style>
.has-gutter {
  /* background-color: red !important; */
}
</style>
<style lang='scss' scoped>
.maina {
  background-color: #f5f5f5;

  .content {
    margin-top: 10px;
    background-color: white !important;

    .content_box {
      padding-left: 15px;

      .title_left {
        margin-left: 20px;
        padding-top: 31px;
        font-size: 16px;
        font-family: Microsoft YaHei, Microsoft YaHei;
        font-weight: 700;
        color: #3D3D3D;
        line-height: 21px;
      }
    }
  }
}
</style>